<template>
	<view class="back-view">

		<view class="scrollview-back">
			<view class="item-back" v-for="(item,index) in list" :key="index">
				<view class="item-back-back" @click="clickItemAction(item)">
					<image class="item-image" :src="item.picUrlsImage" ></image>
					<view class="item-name">{{item.name}}</view>
					<view class="item-des">可咨询领域：{{item.domainDict==-1 ? '不限':item.domainDict}}</view>
					<view class="item-money">¥{{item.price}}</view>
				</view>

			</view>
		</view>
		<uni-load-more iconType="auto" :status="status" />
		<goodsDetail v-if="showDetail" :selectID='selectID'  @goodDeatilClose='goodDeatilClose'></goodsDetail>
		<associateCustomer v-if="showAssciate"></associateCustomer>
	</view>
</template>

<script>
	import goodsDetail from "@/packageC/PhonePC/buyServe/goodsDetail.vue"
	import associateCustomer from "@/packageC/PhonePC/buyServe/associateCustomer.vue"
	export default {
		components: {
			goodsDetail,
			associateCustomer
		},
		data() {
			return {
				list: [],
				status: 'more', //
				showDetail: false, //显示商品详情
				showAssciate: false, //显示关联客户
				page: 1,
				size: 9,
				total: 0,
				selectID:''
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		onPullDownRefresh() {
			//uni.stopPullDownRefresh()  结束刷新	
			this.page = 1;
			this.getGoodsList()
			
		},
		onReachBottom() {
			console.log('加载中')
			this.page += 1;
			this.status = 'loading'
			this.getGoodsList()
		},
		methods: {

			/**
			 * 加载列表
			 */
			async getGoodsList() {
				console.log('getGoodsList')
				let _this = this
				let parmars = {
					page: _this.page,
					size: _this.size
				}
				const res = await _this.$myRequest({
					url: "/client/goods/list",
					data: parmars,
					method: 'POST', //默认是GET
				})
				console.log('列表', res)
				if (res.data.code == 200) {
					let list = res.data.data.list
					if(res.data.data.list.length < _this.size){
						_this.status = 'noMore' //没有更多
					}else{
						_this.status = 'more'
					}
					let newList=[];
					newList = list.map((obj, index) => {
						obj.picUrlsImage = _this.$imageUrls({
							picUrls: obj.picUrls,
							height:600
						})
						obj.price = (obj.price / 100).toFixed(2)
						return obj;
					})
					if(_this.page == 1){
						_this.list=newList;
					}else{
					_this.list=[..._this.list,...newList]	
					}
				}
				uni.stopPullDownRefresh() // 结束刷新	
			},

			clickItemAction(e) {
				console.log(e)
				this.selectID = e.id
				this.showDetail = true;
			},

			goodDeatilClose() {
				this.showDetail = false;
			}

		},
	}
</script>


<style>
	page:before {
		content: '';
		position: fixed;
		left: 0;
		top: 0px;
		width: 100%;
		height: 2px;
		background-color: #eee;
		z-index: 9999;
	}

	.back-view {
		/* 	display: flex;
		justify-content: center; */
	}

	.scrollview-back {
		display: flex;

		flex-wrap: wrap;
		z-index: 1;
	}

	.item-back {
		width: 25%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.item-back-back {
		width: 80%;
		display: flex;
		flex-direction: column;
		margin-top: 20px;
	}

	.item-image {
		width: 100%;
		height: 200px;
		box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.4);
		border-radius: 4px;
		border: 1px solid #EEEEEE;
	}

	.item-name {
		margin-top: 10px;
		font-size: 14px;
		font-weight: 600;
		color: #333333;
	}

	.item-des {
		font-size: 12px;
		font-weight: 400;
		color: #999999;
	}

	.item-money {
		font-size: 20px;
		font-weight: 600;
		color: #F35C22;
	}
</style>
